/*
 * Huawei Software Technologies Co., Ltd. Copyright 1998-2009, All rights reserved.
 * 文件名  :CtmsSoapBindingSkeleton.java
 * 创建人  :flydra
 * 创建时间:2017年1月4日09:35:09
 */
package com.cimp.service.c2.server;

import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;

import javax.xml.namespace.QName;

import org.apache.axis.description.OperationDesc;
import org.apache.axis.description.ParameterDesc;
import org.apache.axis.wsdl.Skeleton;


/**
 * [简要描述]:CMS结果响应框架类<br/>
 * [详细描述]:CMS结果响应框架类<br/>
 *
 * @author yuebinyao
 * @version [revision], 2017年1月4日09:35:14
 * @since IPTV-CIMP-V100R003C02B760
 */
public class CtmsSoapBindingSkeleton implements CSPResponse, Skeleton {

    /**
     * 序列化
     */
    private static final long serialVersionUID = 3832932443858424512L;

    private CSPResponse impl;

    private static Map _myOperations = new Hashtable();

    private static Collection _myOperationsList = new ArrayList();

    /**
     * 工单Facade接口
     */
//    @Resource
//    private transient NoteManagementFacade noteManagementFacade;

    static {
        ParameterDesc[] _params = {new ParameterDesc(new QName("", "CSPID"), (byte) 1, new QName("http://schemas.xmlsoap.org/soap/encoding/", "string"), String.class, false, false), new ParameterDesc(new QName("", "LSPID"), (byte) 1, new QName("http://schemas.xmlsoap.org/soap/encoding/", "string"), String.class, false, false), new ParameterDesc(new QName("", "CorrelateID"), (byte) 1, new QName("http://schemas.xmlsoap.org/soap/encoding/", "string"), String.class, false, false), new ParameterDesc(new QName("", "CmdResult"), (byte) 1, new QName("http://www.w3.org/2001/XMLSchema", "int"), Integer.TYPE, false, false), new ParameterDesc(new QName("", "ResultFileURL"), (byte) 1, new QName("http://schemas.xmlsoap.org/soap/encoding/", "string"), String.class, false, false)};

        OperationDesc oper = new OperationDesc("resultNotify", _params, new QName("", "ResultNotifyReturn"));

        oper.setReturnType(new QName("iptv", "CSPResult"));
        oper.setElementQName(new QName("iptv", "ResultNotify"));
        oper.setSoapAction("");
        _myOperationsList.add(oper);

        if (_myOperations.get("resultNotify") == null) {
            _myOperations.put("resultNotify", new ArrayList());
        }
        ((List) _myOperations.get("resultNotify")).add(oper);
    }

    /**
     * [简要描述]:<br/>
     * [详细描述]:<br/>
     */
    public CtmsSoapBindingSkeleton() {
        this.impl = new CtmsSoapBindingImpl();
    }

    /**
     * [简要描述]:<br/>
     * [详细描述]:<br/>
     *
     * @param impl CSPResponse
     */
    public CtmsSoapBindingSkeleton(CSPResponse impl) {
        this.impl = impl;
    }

    /**
     * [简要描述]:<br/>
     * [详细描述]:<br/>
     *
     * @param methodName String
     * @return List
     * @throws
     */
    public static List getOperationDescByName(String methodName) {
        return (List) _myOperations.get(methodName);
    }

    /**
     * [简要描述]:<br/>
     * [详细描述]:<br/>
     *
     * @return Collection
     * @throws
     */
    public static Collection getOperationDescs() {
        return _myOperationsList;
    }

    /**
     * [简要描述]:<br/>
     * [详细描述]:<br/>
     *
     * @param cspId         String
     * @param lspId         String
     * @param correlateID   String
     * @param cmdResult     int
     * @param resultFileURL String
     * @return CSPResult
     * @throws RemoteException RemoteException
     */
    @Override
    public CSPResult resultNotify(String cspId, String lspId, String correlateID, int cmdResult, String resultFileURL) throws RemoteException {
        return this.impl.resultNotify(cspId, lspId, correlateID, cmdResult, MappingReturnSoap(resultFileURL, lspId));
    }

    /**
     * author flydra
     * 返回结果地址ftp替换
     *
     * @param resultFileURL
     * @return
     */
    private String MappingReturnSoap(String resultFileURL, String lspId) {
//		String pointId=noteManagementFacade.queryPointIdByCorrelateID(correlateID);
       /* if (CmsConfig.getSmgResponseMappingAddress(lspId) == null || CmsConfig.getSmgResponseMappingAddress(lspId).size() <= 0) {
            return resultFileURL;
        } else {*/
        return replaceResultURL(resultFileURL, lspId);
//        }
    }

    //替换结果文件地址
    private String replaceResultURL(String resultFileURL, String lspId) {
        //List<String> list = CmsConfig.getSmgResponseMappingAddress(lspId);
        int begin = resultFileURL.indexOf("://");
        int end = resultFileURL.lastIndexOf("@");

        try {
            //由于暂定只替换返回结果文件中的IP，不替换用户名密码
            String URL = resultFileURL.substring(0, end)
            				/*+ list.get(0)
            				+ ":" + list.get(1)*/ + "@" + "192.168.27.115" + resultFileURL.substring(end).substring(resultFileURL.substring(end).indexOf("/"));

            return URL;
        } catch (Exception e) {
            return resultFileURL;
        }
    }
}
